package com.IR.user.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.IR.oss.util.MyDateProcessor;
import com.IR.shop.po.Users;
import com.IR.user.service.BUsersBiz;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

@Controller
public class BUsersAction {
	@Resource
	public BUsersBiz biz;
	private Users users;
	private List<Users> list;
	public Users getUsers() {
		return users;
	}
	public void setUsers(Users users) {
		this.users = users;
	}
	public List<Users> getList() {
		return list;
	}
	public void setList(List<Users> list) {
		this.list = list;
	}
	
	@RequestMapping(value="/showUserPage.do")
	public void showUserPage(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		int pagenow=new Integer(request.getParameter("pagenow"));
		int pagesize=new Integer(request.getParameter("pagesize"));
		list=biz.showUserPage(pagenow, pagesize);
		PrintWriter out = response.getWriter();		
		MyDateProcessor mydate=new MyDateProcessor();
		//MyDateProcessor mydate=new MyDateProcessor("yyyy-MM-dd hh:mm:ss");
		JsonConfig config=new JsonConfig();
		config.registerJsonValueProcessor("userdate", mydate);		
		String str = JSONArray.fromObject(list,config).toString();
		//System.out.println(str);
		out.println(str); 
		//System.out.println(list.size());
	}
	@RequestMapping(value="/showUserById.do")
	public void showUserId(HttpServletRequest request,HttpServletResponse response) throws IOException  {
		//System.out.println("sssssssssssssssssssss");
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long userid=new Long(request.getParameter("userid"));
		users=biz.showUserById(userid);
		PrintWriter out = response.getWriter();		
		MyDateProcessor mydate=new MyDateProcessor();
		//MyDateProcessor mydate=new MyDateProcessor("yyyy-MM-dd hh:mm:ss");
		JsonConfig config=new JsonConfig();
		config.registerJsonValueProcessor("userdate", mydate);		
		String str = JSONObject.fromObject(users,config).toString();
		System.out.println(str);
		out.println(str); 
	
		//String str=JSONObject.fromObject(users).toString();
		//return "1";
	}
}
